{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-06-23T11:27:17.133431Z",
     "start_time": "2023-06-23T11:27:17.078601Z"
    },
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-06-23T11:27:17.138894Z",
     "start_time": "2023-06-23T11:27:17.085160Z"
    },
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "InPath = 'F:/NDSucess/csv/'\n",
    "OutPath = 'F:/NDDeal/csv/'\n",
    "# fileName = 'fanthreegrade1.csv'\n",
    "# InPath = 'F:/tempdata/'\n",
    "# OutPath = 'F:/ND/'\n",
    "fileName = 'small_humidifier_maxpower1.csv'"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-06-23T11:27:37.341151Z",
     "start_time": "2023-06-23T11:27:17.110078Z"
    },
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>DeviceTime</th>\n",
       "      <th>HomeID</th>\n",
       "      <th>RecvTime</th>\n",
       "      <th>InternalIndex</th>\n",
       "      <th>Channel</th>\n",
       "      <th>Rate</th>\n",
       "      <th>Value</th>\n",
       "      <th>Note</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>95</td>\n",
       "      <td>2023/06/12 13:22:39</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 09:06:00.335529</td>\n",
       "      <td>93</td>\n",
       "      <td>1</td>\n",
       "      <td>1024</td>\n",
       "      <td>433|408|385|361|337|314|290|267|243|219|195|16...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>96</td>\n",
       "      <td>2023/06/12 13:22:39</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 09:06:00.355893</td>\n",
       "      <td>93</td>\n",
       "      <td>2</td>\n",
       "      <td>1024</td>\n",
       "      <td>-19|-20|-20|-21|-20|-21|-20|-20|-20|-21|-20|-2...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>97</td>\n",
       "      <td>2023/06/12 13:22:39</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 09:06:00.356961</td>\n",
       "      <td>94</td>\n",
       "      <td>1</td>\n",
       "      <td>1024</td>\n",
       "      <td>442|418|396|372|349|325|300|276|252|226|199|17...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>98</td>\n",
       "      <td>2023/06/12 13:22:39</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 09:06:00.358356</td>\n",
       "      <td>94</td>\n",
       "      <td>2</td>\n",
       "      <td>1024</td>\n",
       "      <td>-19|-19|-19|-21|-19|-20|-20|-21|-21|-21|-20|-1...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>99</td>\n",
       "      <td>2023/06/12 13:22:39</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 09:06:00.376447</td>\n",
       "      <td>95</td>\n",
       "      <td>1</td>\n",
       "      <td>1024</td>\n",
       "      <td>443|417|391|364|337|312|286|258|232|206|178|15...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>444083</th>\n",
       "      <td>444178</td>\n",
       "      <td>2023/06/12 14:36:37</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 10:19:59.258468</td>\n",
       "      <td>182</td>\n",
       "      <td>2</td>\n",
       "      <td>1024</td>\n",
       "      <td>-508|-590|-645|-682|-711|-735|-754|-771|-785|-...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>444084</th>\n",
       "      <td>444179</td>\n",
       "      <td>2023/06/12 14:36:37</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 10:19:59.276726</td>\n",
       "      <td>183</td>\n",
       "      <td>1</td>\n",
       "      <td>1024</td>\n",
       "      <td>-3807|-3818|-3827|-3837|-3847|-3858|-3868|-388...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>444085</th>\n",
       "      <td>444180</td>\n",
       "      <td>2023/06/12 14:36:37</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 10:19:59.296428</td>\n",
       "      <td>183</td>\n",
       "      <td>2</td>\n",
       "      <td>1024</td>\n",
       "      <td>-497|-584|-640|-679|-707|-726|-745|-761|-776|-...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>444086</th>\n",
       "      <td>444181</td>\n",
       "      <td>2023/06/12 14:36:37</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 10:19:59.297468</td>\n",
       "      <td>184</td>\n",
       "      <td>1</td>\n",
       "      <td>1024</td>\n",
       "      <td>-3798|-3807|-3816|-3826|-3836|-3848|-3858|-386...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>444087</th>\n",
       "      <td>444182</td>\n",
       "      <td>2023/06/12 14:36:37</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 10:19:59.298435</td>\n",
       "      <td>184</td>\n",
       "      <td>2</td>\n",
       "      <td>1024</td>\n",
       "      <td>-366|-496|-582|-639|-681|-713|-741|-763|-783|-...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>444088 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            id           DeviceTime  HomeID                    RecvTime   \n",
       "0           95  2023/06/12 13:22:39       1  2023/08/20 09:06:00.335529  \\\n",
       "1           96  2023/06/12 13:22:39       1  2023/08/20 09:06:00.355893   \n",
       "2           97  2023/06/12 13:22:39       1  2023/08/20 09:06:00.356961   \n",
       "3           98  2023/06/12 13:22:39       1  2023/08/20 09:06:00.358356   \n",
       "4           99  2023/06/12 13:22:39       1  2023/08/20 09:06:00.376447   \n",
       "...        ...                  ...     ...                         ...   \n",
       "444083  444178  2023/06/12 14:36:37       1  2023/08/20 10:19:59.258468   \n",
       "444084  444179  2023/06/12 14:36:37       1  2023/08/20 10:19:59.276726   \n",
       "444085  444180  2023/06/12 14:36:37       1  2023/08/20 10:19:59.296428   \n",
       "444086  444181  2023/06/12 14:36:37       1  2023/08/20 10:19:59.297468   \n",
       "444087  444182  2023/06/12 14:36:37       1  2023/08/20 10:19:59.298435   \n",
       "\n",
       "        InternalIndex  Channel  Rate   \n",
       "0                  93        1  1024  \\\n",
       "1                  93        2  1024   \n",
       "2                  94        1  1024   \n",
       "3                  94        2  1024   \n",
       "4                  95        1  1024   \n",
       "...               ...      ...   ...   \n",
       "444083            182        2  1024   \n",
       "444084            183        1  1024   \n",
       "444085            183        2  1024   \n",
       "444086            184        1  1024   \n",
       "444087            184        2  1024   \n",
       "\n",
       "                                                    Value  Note  \n",
       "0       433|408|385|361|337|314|290|267|243|219|195|16...   NaN  \n",
       "1       -19|-20|-20|-21|-20|-21|-20|-20|-20|-21|-20|-2...   NaN  \n",
       "2       442|418|396|372|349|325|300|276|252|226|199|17...   NaN  \n",
       "3       -19|-19|-19|-21|-19|-20|-20|-21|-21|-21|-20|-1...   NaN  \n",
       "4       443|417|391|364|337|312|286|258|232|206|178|15...   NaN  \n",
       "...                                                   ...   ...  \n",
       "444083  -508|-590|-645|-682|-711|-735|-754|-771|-785|-...   NaN  \n",
       "444084  -3807|-3818|-3827|-3837|-3847|-3858|-3868|-388...   NaN  \n",
       "444085  -497|-584|-640|-679|-707|-726|-745|-761|-776|-...   NaN  \n",
       "444086  -3798|-3807|-3816|-3826|-3836|-3848|-3858|-386...   NaN  \n",
       "444087  -366|-496|-582|-639|-681|-713|-741|-763|-783|-...   NaN  \n",
       "\n",
       "[444088 rows x 9 columns]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv(InPath + fileName)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-06-23T11:27:37.484900Z",
     "start_time": "2023-06-23T11:27:37.329576Z"
    },
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>DeviceTime</th>\n",
       "      <th>HomeID</th>\n",
       "      <th>RecvTime</th>\n",
       "      <th>InternalIndex</th>\n",
       "      <th>Channel</th>\n",
       "      <th>Rate</th>\n",
       "      <th>Value</th>\n",
       "      <th>Note</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>95</td>\n",
       "      <td>2023/06/12 13:22:39</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 09:06:00.335529</td>\n",
       "      <td>93</td>\n",
       "      <td>1</td>\n",
       "      <td>1024</td>\n",
       "      <td>433|408|385|361|337|314|290|267|243|219|195|16...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>96</td>\n",
       "      <td>2023/06/12 13:22:39</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 09:06:00.355893</td>\n",
       "      <td>93</td>\n",
       "      <td>2</td>\n",
       "      <td>1024</td>\n",
       "      <td>-19|-20|-20|-21|-20|-21|-20|-20|-20|-21|-20|-2...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>97</td>\n",
       "      <td>2023/06/12 13:22:39</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 09:06:00.356961</td>\n",
       "      <td>94</td>\n",
       "      <td>1</td>\n",
       "      <td>1024</td>\n",
       "      <td>442|418|396|372|349|325|300|276|252|226|199|17...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>98</td>\n",
       "      <td>2023/06/12 13:22:39</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 09:06:00.358356</td>\n",
       "      <td>94</td>\n",
       "      <td>2</td>\n",
       "      <td>1024</td>\n",
       "      <td>-19|-19|-19|-21|-19|-20|-20|-21|-21|-21|-20|-1...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>99</td>\n",
       "      <td>2023/06/12 13:22:39</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 09:06:00.376447</td>\n",
       "      <td>95</td>\n",
       "      <td>1</td>\n",
       "      <td>1024</td>\n",
       "      <td>443|417|391|364|337|312|286|258|232|206|178|15...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>444083</th>\n",
       "      <td>444178</td>\n",
       "      <td>2023/06/12 14:36:37</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 10:19:59.258468</td>\n",
       "      <td>182</td>\n",
       "      <td>2</td>\n",
       "      <td>1024</td>\n",
       "      <td>-508|-590|-645|-682|-711|-735|-754|-771|-785|-...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>444084</th>\n",
       "      <td>444179</td>\n",
       "      <td>2023/06/12 14:36:37</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 10:19:59.276726</td>\n",
       "      <td>183</td>\n",
       "      <td>1</td>\n",
       "      <td>1024</td>\n",
       "      <td>-3807|-3818|-3827|-3837|-3847|-3858|-3868|-388...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>444085</th>\n",
       "      <td>444180</td>\n",
       "      <td>2023/06/12 14:36:37</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 10:19:59.296428</td>\n",
       "      <td>183</td>\n",
       "      <td>2</td>\n",
       "      <td>1024</td>\n",
       "      <td>-497|-584|-640|-679|-707|-726|-745|-761|-776|-...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>444086</th>\n",
       "      <td>444181</td>\n",
       "      <td>2023/06/12 14:36:37</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 10:19:59.297468</td>\n",
       "      <td>184</td>\n",
       "      <td>1</td>\n",
       "      <td>1024</td>\n",
       "      <td>-3798|-3807|-3816|-3826|-3836|-3848|-3858|-386...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>444087</th>\n",
       "      <td>444182</td>\n",
       "      <td>2023/06/12 14:36:37</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 10:19:59.298435</td>\n",
       "      <td>184</td>\n",
       "      <td>2</td>\n",
       "      <td>1024</td>\n",
       "      <td>-366|-496|-582|-639|-681|-713|-741|-763|-783|-...</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>444088 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            id           DeviceTime  HomeID                    RecvTime   \n",
       "0           95  2023/06/12 13:22:39       1  2023/08/20 09:06:00.335529  \\\n",
       "1           96  2023/06/12 13:22:39       1  2023/08/20 09:06:00.355893   \n",
       "2           97  2023/06/12 13:22:39       1  2023/08/20 09:06:00.356961   \n",
       "3           98  2023/06/12 13:22:39       1  2023/08/20 09:06:00.358356   \n",
       "4           99  2023/06/12 13:22:39       1  2023/08/20 09:06:00.376447   \n",
       "...        ...                  ...     ...                         ...   \n",
       "444083  444178  2023/06/12 14:36:37       1  2023/08/20 10:19:59.258468   \n",
       "444084  444179  2023/06/12 14:36:37       1  2023/08/20 10:19:59.276726   \n",
       "444085  444180  2023/06/12 14:36:37       1  2023/08/20 10:19:59.296428   \n",
       "444086  444181  2023/06/12 14:36:37       1  2023/08/20 10:19:59.297468   \n",
       "444087  444182  2023/06/12 14:36:37       1  2023/08/20 10:19:59.298435   \n",
       "\n",
       "        InternalIndex  Channel  Rate   \n",
       "0                  93        1  1024  \\\n",
       "1                  93        2  1024   \n",
       "2                  94        1  1024   \n",
       "3                  94        2  1024   \n",
       "4                  95        1  1024   \n",
       "...               ...      ...   ...   \n",
       "444083            182        2  1024   \n",
       "444084            183        1  1024   \n",
       "444085            183        2  1024   \n",
       "444086            184        1  1024   \n",
       "444087            184        2  1024   \n",
       "\n",
       "                                                    Value  Note  \n",
       "0       433|408|385|361|337|314|290|267|243|219|195|16...   NaN  \n",
       "1       -19|-20|-20|-21|-20|-21|-20|-20|-20|-21|-20|-2...   NaN  \n",
       "2       442|418|396|372|349|325|300|276|252|226|199|17...   NaN  \n",
       "3       -19|-19|-19|-21|-19|-20|-20|-21|-21|-21|-20|-1...   NaN  \n",
       "4       443|417|391|364|337|312|286|258|232|206|178|15...   NaN  \n",
       "...                                                   ...   ...  \n",
       "444083  -508|-590|-645|-682|-711|-735|-754|-771|-785|-...   NaN  \n",
       "444084  -3807|-3818|-3827|-3837|-3847|-3858|-3868|-388...   NaN  \n",
       "444085  -497|-584|-640|-679|-707|-726|-745|-761|-776|-...   NaN  \n",
       "444086  -3798|-3807|-3816|-3826|-3836|-3848|-3858|-386...   NaN  \n",
       "444087  -366|-496|-582|-639|-681|-713|-741|-763|-783|-...   NaN  \n",
       "\n",
       "[444088 rows x 9 columns]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "# 表示pd按照\"feature_name\"这个字段排序;\n",
    "#\n",
    "# inplace：默认为False,如果该值为False，那么原来的pd顺序没变，只是返回的是排序的；\n",
    "#\n",
    "# ascending：默认为True，按照升序排序，为False时，按照降序排序。\n",
    "\n",
    "df_RecvTimeSort = df.sort_values(by=[\"DeviceTime\",\"InternalIndex\"],inplace=False,ascending=[True,True])\n",
    "df_RecvTimeSort"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-06-23T11:27:48.373529Z",
     "start_time": "2023-06-23T11:27:43.217447Z"
    },
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(444088, 222044.0)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "DataList = []\n",
    "for row in df_RecvTimeSort.itertuples():\n",
    "    DataList.append(row)\n",
    "len(DataList),len(DataList)/2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-06-23T11:28:33.586687Z",
     "start_time": "2023-06-23T11:27:48.391789Z"
    },
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'str'>\n",
      "222044 0\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>DeviceTime</th>\n",
       "      <th>HomeID</th>\n",
       "      <th>RecvTime</th>\n",
       "      <th>InternalIndex</th>\n",
       "      <th>Channel</th>\n",
       "      <th>Rate</th>\n",
       "      <th>Value</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>2023/06/12 13:22:39</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 09:06:00.335529</td>\n",
       "      <td>93</td>\n",
       "      <td>1</td>\n",
       "      <td>1024</td>\n",
       "      <td>433|408|385|361|337|314|290|267|243|219|195|16...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2023/06/12 13:22:39</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 09:06:00.335529</td>\n",
       "      <td>93</td>\n",
       "      <td>2</td>\n",
       "      <td>1024</td>\n",
       "      <td>-19|-20|-20|-21|-20|-21|-20|-20|-20|-21|-20|-2...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>2023/06/12 13:22:39</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 09:06:00.356961</td>\n",
       "      <td>94</td>\n",
       "      <td>1</td>\n",
       "      <td>1024</td>\n",
       "      <td>442|418|396|372|349|325|300|276|252|226|199|17...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>2023/06/12 13:22:39</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 09:06:00.356961</td>\n",
       "      <td>94</td>\n",
       "      <td>2</td>\n",
       "      <td>1024</td>\n",
       "      <td>-19|-19|-19|-21|-19|-20|-20|-21|-21|-21|-20|-1...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>2023/06/12 13:22:39</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 09:06:00.376447</td>\n",
       "      <td>95</td>\n",
       "      <td>1</td>\n",
       "      <td>1024</td>\n",
       "      <td>443|417|391|364|337|312|286|258|232|206|178|15...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>444083</th>\n",
       "      <td>444083</td>\n",
       "      <td>2023/06/12 14:36:37</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 10:19:59.257465</td>\n",
       "      <td>182</td>\n",
       "      <td>2</td>\n",
       "      <td>1024</td>\n",
       "      <td>-508|-590|-645|-682|-711|-735|-754|-771|-785|-...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>444084</th>\n",
       "      <td>444084</td>\n",
       "      <td>2023/06/12 14:36:37</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 10:19:59.276726</td>\n",
       "      <td>183</td>\n",
       "      <td>1</td>\n",
       "      <td>1024</td>\n",
       "      <td>-3807|-3818|-3827|-3837|-3847|-3858|-3868|-388...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>444085</th>\n",
       "      <td>444085</td>\n",
       "      <td>2023/06/12 14:36:37</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 10:19:59.276726</td>\n",
       "      <td>183</td>\n",
       "      <td>2</td>\n",
       "      <td>1024</td>\n",
       "      <td>-497|-584|-640|-679|-707|-726|-745|-761|-776|-...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>444086</th>\n",
       "      <td>444086</td>\n",
       "      <td>2023/06/12 14:36:37</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 10:19:59.297468</td>\n",
       "      <td>184</td>\n",
       "      <td>1</td>\n",
       "      <td>1024</td>\n",
       "      <td>-3798|-3807|-3816|-3826|-3836|-3848|-3858|-386...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>444087</th>\n",
       "      <td>444087</td>\n",
       "      <td>2023/06/12 14:36:37</td>\n",
       "      <td>1</td>\n",
       "      <td>2023/08/20 10:19:59.297468</td>\n",
       "      <td>184</td>\n",
       "      <td>2</td>\n",
       "      <td>1024</td>\n",
       "      <td>-366|-496|-582|-639|-681|-713|-741|-763|-783|-...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>444088 rows × 8 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            id           DeviceTime  HomeID                    RecvTime   \n",
       "0            0  2023/06/12 13:22:39       1  2023/08/20 09:06:00.335529  \\\n",
       "1            1  2023/06/12 13:22:39       1  2023/08/20 09:06:00.335529   \n",
       "2            2  2023/06/12 13:22:39       1  2023/08/20 09:06:00.356961   \n",
       "3            3  2023/06/12 13:22:39       1  2023/08/20 09:06:00.356961   \n",
       "4            4  2023/06/12 13:22:39       1  2023/08/20 09:06:00.376447   \n",
       "...        ...                  ...     ...                         ...   \n",
       "444083  444083  2023/06/12 14:36:37       1  2023/08/20 10:19:59.257465   \n",
       "444084  444084  2023/06/12 14:36:37       1  2023/08/20 10:19:59.276726   \n",
       "444085  444085  2023/06/12 14:36:37       1  2023/08/20 10:19:59.276726   \n",
       "444086  444086  2023/06/12 14:36:37       1  2023/08/20 10:19:59.297468   \n",
       "444087  444087  2023/06/12 14:36:37       1  2023/08/20 10:19:59.297468   \n",
       "\n",
       "        InternalIndex  Channel  Rate   \n",
       "0                  93        1  1024  \\\n",
       "1                  93        2  1024   \n",
       "2                  94        1  1024   \n",
       "3                  94        2  1024   \n",
       "4                  95        1  1024   \n",
       "...               ...      ...   ...   \n",
       "444083            182        2  1024   \n",
       "444084            183        1  1024   \n",
       "444085            183        2  1024   \n",
       "444086            184        1  1024   \n",
       "444087            184        2  1024   \n",
       "\n",
       "                                                    Value  \n",
       "0       433|408|385|361|337|314|290|267|243|219|195|16...  \n",
       "1       -19|-20|-20|-21|-20|-21|-20|-20|-20|-21|-20|-2...  \n",
       "2       442|418|396|372|349|325|300|276|252|226|199|17...  \n",
       "3       -19|-19|-19|-21|-19|-20|-20|-21|-21|-21|-20|-1...  \n",
       "4       443|417|391|364|337|312|286|258|232|206|178|15...  \n",
       "...                                                   ...  \n",
       "444083  -508|-590|-645|-682|-711|-735|-754|-771|-785|-...  \n",
       "444084  -3807|-3818|-3827|-3837|-3847|-3858|-3868|-388...  \n",
       "444085  -497|-584|-640|-679|-707|-726|-745|-761|-776|-...  \n",
       "444086  -3798|-3807|-3816|-3826|-3836|-3848|-3858|-386...  \n",
       "444087  -366|-496|-582|-639|-681|-713|-741|-763|-783|-...  \n",
       "\n",
       "[444088 rows x 8 columns]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "id = []\n",
    "DeviceTime = []\n",
    "HomeID = []\n",
    "RecvTime = []\n",
    "InternalIndex = []\n",
    "Channel = []\n",
    "Rate = []\n",
    "Value = []\n",
    "index = 0\n",
    "Success = 0\n",
    "Error = 0\n",
    "\n",
    "for i in range(0,int(len(DataList)),2):\n",
    "    if i+1 >= int(len(DataList)):\n",
    "        break\n",
    "\n",
    "    Record1 = DataList[i]\n",
    "    Record2 = DataList[i+1]\n",
    "    if int(Record1.InternalIndex) == int(Record2.InternalIndex):\n",
    "        Success = Success + 1\n",
    "        try:\n",
    "            Record1Time = datetime.datetime.strptime(Record1.RecvTime,\"%Y/%m/%d %H:%M:%S.%f\")\n",
    "        except:\n",
    "            print(Record1.RecvTime)\n",
    "            NewRecvTime = Record1.RecvTime+'.000000'\n",
    "            Record1Time = datetime.datetime.strptime(NewRecvTime,\"%Y/%m/%d %H:%M:%S.%f\")\n",
    "\n",
    "        try:\n",
    "            Record2Time = datetime.datetime.strptime(Record2.RecvTime,\"%Y/%m/%d %H:%M:%S.%f\")\n",
    "        except:\n",
    "            print(type(Record2.RecvTime))\n",
    "            NewRecvTime = Record2.RecvTime+'.000000'\n",
    "            Record2Time = datetime.datetime.strptime(NewRecvTime,\"%Y/%m/%d %H:%M:%S.%f\")\n",
    "\n",
    "        CommonTime = min(Record1Time,Record2Time)\n",
    "\n",
    "\n",
    "\n",
    "        id.append(index)\n",
    "        DeviceTime.append(Record1.DeviceTime)\n",
    "        HomeID.append(Record1.HomeID)\n",
    "        RecvTime.append(CommonTime.strftime(\"%Y/%m/%d %H:%M:%S.%f\"))\n",
    "        InternalIndex.append(Record1.InternalIndex)\n",
    "        Channel.append(Record1.Channel)\n",
    "        Rate.append(Record1.Rate)\n",
    "        Value.append(Record1.Value)\n",
    "\n",
    "        index = index + 1\n",
    "\n",
    "        id.append(index)\n",
    "        DeviceTime.append(Record2.DeviceTime)\n",
    "        HomeID.append(Record2.HomeID)\n",
    "        RecvTime.append(CommonTime.strftime(\"%Y/%m/%d %H:%M:%S.%f\"))\n",
    "        InternalIndex.append(Record2.InternalIndex)\n",
    "        Channel.append(Record2.Channel)\n",
    "        Rate.append(Record2.Rate)\n",
    "        Value.append(Record2.Value)\n",
    "        index = index + 1\n",
    "\n",
    "    else:\n",
    "        print(Record1.id,Record2.id)\n",
    "        Error = Error + 1\n",
    "\n",
    "print(Success,Error)\n",
    "SaveDict = {'DeviceTime': DeviceTime, 'HomeID': HomeID, 'RecvTime': RecvTime, 'InternalIndex': InternalIndex, 'Channel': Channel, 'Rate': Rate, 'Value': Value}\n",
    "df_Frame = pd.DataFrame(SaveDict)\n",
    "df_save = df_Frame.sort_values(by=[\"DeviceTime\",\"RecvTime\"],inplace=False,ascending=[True,True])\n",
    "df_save.insert(loc=0,column='id',value=id)\n",
    "df_save.to_csv(OutPath + fileName,index=None)\n",
    "df_save"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-06-23T11:28:34.597565Z",
     "start_time": "2023-06-23T11:28:33.710638Z"
    },
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "222044\n"
     ]
    }
   ],
   "source": [
    "CheckList = []\n",
    "CheckInternalIndex = []\n",
    "successCount = 0\n",
    "for row in df_save.itertuples():\n",
    "    CheckList.append(row)\n",
    "for i in range(0,int(len(CheckList)),2):\n",
    "    Record1 = CheckList[i]\n",
    "    CheckInternalIndex.append(Record1.InternalIndex)\n",
    "count = CheckInternalIndex[0]\n",
    "for i in range(0,len(CheckInternalIndex)):\n",
    "    # print(CheckInternalIndex[i],count,i)\n",
    "    if int(CheckInternalIndex[i]) != count:\n",
    "        print(\"Error\",i)\n",
    "    else:\n",
    "        successCount = successCount + 1\n",
    "    count = (count+1)%256\n",
    "print(successCount)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-06-23T11:28:34.597565Z",
     "start_time": "2023-06-23T11:28:34.589922Z"
    },
    "collapsed": false
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-06-23T11:28:34.597565Z",
     "start_time": "2023-06-23T11:28:34.594410Z"
    },
    "collapsed": false
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-06-23T11:28:34.599553Z",
     "start_time": "2023-06-23T11:28:34.597557Z"
    },
    "collapsed": false
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-06-23T11:28:34.602057Z",
     "start_time": "2023-06-23T11:28:34.602057Z"
    },
    "collapsed": false
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-06-23T11:28:34.605553Z",
     "start_time": "2023-06-23T11:28:34.604051Z"
    },
    "collapsed": false
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
